from selenium import webdriver
import time
from selenium.webdriver.common.by import By
import pywinauto


driver = webdriver.Chrome("C:\Program Files\driver\chromedriver.exe")
driver.maximize_window()
# 打开网易见外工作台
driver.get("https://jianwai.youdao.com/")
time.sleep(2)

# 先定位到表单元素
element_iframe = driver.find_element(By.CSS_SELECTOR, "iframe[id]")
# 切换进入表单
# driver.switch_to_frame(element_iframe)
driver.switch_to.frame(element_iframe)

# 账号输入框输入邮箱
driver.find_element(By.CSS_SELECTOR, "input[name=email]").send_keys("974381044@qq.com")
# 密码输入框输入密码
driver.find_element(By.XPATH, "//input[@name='password']").send_keys("zytc@12310120")
# 点击-登录
driver.find_element(By.ID, "dologin").click()
time.sleep(10)

# 点击-新建项目
driver.find_element(By.XPATH, "//div[text()='新建项目']").click()
# 点击-图片翻译
driver.find_element(By.XPATH, "//div[text()='图片翻译']/..").click()
time.sleep(1)

# # 文件上传，input标签定位到元素直接send_keys()就行
# driver.find_element(By.CSS_SELECTOR, "input[class=file]").send_keys("C:\TT\习知\课件\我的课件\\1624958787(1).png")
# 非input标签，用pywinauto
# 定位元素，点击，打开-【打开】控件
driver.find_element(By.XPATH, "//input[@class='file']/..").click()
time.sleep(2)
# 通过窗口打开
app = pywinauto.Desktop()
# 通过弹框名称进入控件中
win = app['打开']
# 输入上传图片的地址
win['Edit'].type_keys(r'C:\TT\习知\课件\我的课件\1624958787.png')
time.sleep(2)
#点击打开按钮
win['Button'].click()

time.sleep(5)
driver.quit()